package com.zonski.jbots.desktop.client.entity;

import java.util.HashMap;

import com.zonski.jbots.engine.Entity;
import com.zonski.jbots.engine.EntityType;

import com.zonski.jbots.desktop.client.EntityRenderer;
import com.zonski.jbots.desktop.client.EntityRendererFactory;

public final class HashedEntityRendererFactory implements EntityRendererFactory
{
    private EntityRenderer defaultRenderer;
    private HashMap renderers;

    public HashedEntityRendererFactory()
    {
        this.renderers = new HashMap();
    }

    public final void addRenderer(String typeName, EntityRenderer renderer)
    {
        this.renderers.put(typeName, renderer);
    }

    public final EntityRenderer getRenderer(Entity entity)
    {
        String name = entity.entityType.getName();
        return getRenderer(name);
    }

    public final EntityRenderer getRenderer(String name)
    {
        EntityRenderer renderer = (EntityRenderer)this.renderers.get(name);
        if(renderer == null)
        {
            renderer = this.defaultRenderer;
        }
        return renderer;
    }

    public final void setDefaultRenderer(EntityRenderer defaultRenderer)
    {
        this.defaultRenderer = defaultRenderer;
    }

    public final EntityRenderer getDefaultRenderer()
    {
        return this.defaultRenderer;
    }
}
